package com.example.dense_rack_server.service;

import cn.hutool.core.util.StrUtil;
import com.example.dense_rack_server.entity.Host;
import com.example.dense_rack_server.mapper.HostMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 设备主机 服务实现类
 * </p>
 *
 * @author  张彬 
 * @since 2025-03-05
 */
@Service
public class HostService extends ServiceImpl<HostMapper, Host> {

    @Resource
    private HostMapper hostMapper;




    /**
     * 获取区域列表
     */
    public Map<String, Object> listTable(String areaId, int page, int limit) {
        Map<String, Object> paramsMap = new HashMap<>();
        int offset = (page - 1) * limit;
        paramsMap.put("page", offset);
        paramsMap.put("limit", limit);
        if (StrUtil.isNotEmpty(areaId)) {
            paramsMap.put("areaId", areaId);
        }
        List<Map<String, Object>> mapList = hostMapper.selectTablePage(paramsMap);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "数据请求成功");
        map.put("count", hostMapper.selectTablePageCount(paramsMap));
        map.put("data", mapList);
        return map;
    }

}
